<script setup>
import api from "./api.js";
import CompanyEditDialog from "./CompanyEditDialog.vue";


const tableData = ref([])
const paging = reactive({
  total: 1,
  pageNum: 1,
  pageSize: 10,
})
const tableRef = ref()
const companyEditDialog = ref();


function handleCompany() {
  companyEditDialog.value.open();
}

function getList() {
  api.list().then(response => {
    tableData.value = response.records;
    paging.total = response.total;
    paging.pageNum = response.current;
  }).catch(error => {
    console.log(error);
  });
}

onMounted(()=> {
  getList();
})

</script>

<template>
  <div class="app-container">
    <div class="toolbar-section">
      <el-button  @click="handleCompany">增加</el-button>
    </div>
    <div class="table-section">
      <vxe-table style="height: 100%;"
                 border="full"
                 ref="tableRef"
                 :column-config="{resizable: true}"
                 :data="tableData">
        <vxe-column field="name" title="名称" tree-node></vxe-column>
        <vxe-column field="code" title="编码"></vxe-column>
        <vxe-column field="type" title="类型"></vxe-column>
        <vxe-column field="leader" title="负责人"></vxe-column>
      </vxe-table>
    </div>
    <div class="pagination-section">
      <pagination
          v-show="paging.total>0"
          :total="paging.total"
          v-model:page="paging.pageNum"
          v-model:limit="paging.pageSize"
          @pagination="getList"
      />
    </div>
    <company-edit-dialog ref="companyEditDialog" @sub="getList"></company-edit-dialog>
  </div>
</template>

<style scoped lang="scss">
  .organization-structure-main {
    box-sizing: border-box;
    padding: 15px;
  }
</style>